package reflect;

import java.util.Scanner;

/**
 * 使用反射机制实例化对象
 */
public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {

//        Class cls = Class.forName("reflect.Person");
//        Object obj = cls.newInstance();
//        System.out.println(obj);

        Scanner scanner = new Scanner(System.in);
        System.out.println("输入类名");
        String className = scanner.nextLine();
        Class cls = Class.forName(className);
        Object obj = cls.newInstance();
        System.out.println(obj);
    }
}
